﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Reflection;
using System.Text;
using T.FAS.Runtime.Base.Entity;
using T.FAS.Runtime.Expression.Entity;
using T.ServiceComponent.DAC.Service;
using T.ServiceComponent.Database.Service;

namespace T.FAS.Runtime.Expression.Dev.Dao
{
    public class ExprFuncItemParamDao : DaoService<ExprFuncItemParam>
    {
        public ExprFuncItemParamDao() :
           base()
        {
            DBName = "TFAS";
        }

        public override string TableName => "FAS_ExprFuncItemParam";
        public override string IDColumnName => "ExprItemID";
        public override Dictionary<string, object> GetDataMapping(ExprFuncItemParam data)
        {
            var datas = base.GetDataMapping(data);
            datas.Remove("DataType");
            datas.Add("DataType", (int)(data.DataType));
            return datas;
        }
        public override List<string> ExceptColumnName => new List<string> {  "ExprExt" };
        public override ExprFuncItemParam ConvertToObject(Dictionary<string, PropertyInfo> columns, DataRow row)
        {
            var myCol = new Dictionary<string, PropertyInfo>(base.Columns);
            myCol.Remove("DataType");
            var data = base.ConvertToObject(myCol, row);
            if (row["DataType"] != DBNull.Value)
                data.DataType = (DataType)Enum.Parse(typeof(DataType),
                                                Convert.ToString(row["DataType"]));
            return data;
        }
        public List<ExprFuncItemParam> GetExprFuncItemParams()
        {
            var result = new List<ExprFuncItemParam>();
            List<object> objects = base.GetObjectsByFilter("1=1");
            if (objects != null)
            {
                objects.ForEach(obj => result.Add(obj as ExprFuncItemParam));
            }
            return result;
        }
        public List<ExprFuncItemParam> GetExprFuncItemParams(string exprItemID)
        {
            var result = new List<ExprFuncItemParam>();
            List<object> objects = base.GetObjectsByFilter(string.Format("exprItemID='{0}'", exprItemID));
            if (objects != null)
            {
                objects.ForEach(obj => result.Add(obj as ExprFuncItemParam));
            }
            return result;
        }
    }
}
